﻿<?php 
session_start();
if (!isset ($_SESSION["id"])) {
	session_destroy();
	echo "<script language='javascript'>top.location.href = 'Login.php';</script>";
	exit;
}
	include_once 'public/DB_Oracle.php';
	include_once 'public/page/page.class.php';
	$DBsql = new DB_Oracle ();
	//当前用户组的权限
	$index=$_GET['id'];
	$sql="select * from sys_permission sp where sp.permission_index=$index";
	$resu=$DBsql->fetch_one_array($sql);
	$uiId=$resu['WEB_UI'];
	if(isset($uiId)||!empty($uiId)){
		$groupRe=explode(',',$uiId);
	}
	//所有菜单
	$sql="select * from sys_web_ui t where t.WEB_UI_VALID=1";
	$rows=$DBsql->fetch_all_array($sql);
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script>
<div class="manageTab">
  <table width="100%" border="0" cellspacing="0" cellpadding="0"
	align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25"
			width="8" /></td>
      <td style="background: #3980b2;" valign="middle" height="16"><div class="use_righgDiv"><span>
          <input type="checkbox" id="checkall" name="checkbox1" value="checkbox" onclick='checkA();' />
          全选</span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">权限管理列表</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background: #3980b2;">&nbsp;</td>
      <td><div class="tdfff">
          <ul class="manage_ul">
          <?php 
          	foreach ($rows as $key=>$row){
          		if($row['WEB_UI_ID']==0){
          ?>
            <li>
              <h1>
                <input name="checkbox" type="checkbox" class="STYLE2" value="<?php echo $row['WEB_UI_INDEX'];?>"
                	<?php 
                		//查询当前用户组的权限
                		if(!empty($groupRe)){
	                		foreach ($groupRe as $group){
	                			if($group==$row['WEB_UI_INDEX']){
	                				echo 'checked';
	                			}
	                		}
	                	}
                	?>
                 id="check<?php echo $row['WEB_UI_INDEX'];?>" onclick="checkAllType('check<?php echo $row['WEB_UI_INDEX'];?>', 'check<?php echo $row['WEB_UI_INDEX'];?>Box')" />
                <?php echo $row['WEB_UI_NAME'];?></h1>
              <ul id="check<?php echo $row['WEB_UI_INDEX'];?>Box">
                <?php 
                	$sql="select * from sys_web_ui swu where swu.web_ui_id=".$row['WEB_UI_INDEX'];
                	$resus=$DBsql->fetch_all_array($sql);
                	foreach ($resus as $resu){
                ?>
                <li>
                  <input name="checkbox" type="checkbox" id="checkChild<?php echo $row['WEB_UI_INDEX'];?>"
                  	<?php 
                		//查询当前用户组的权限
                		if(!empty($groupRe)){
	                		foreach ($groupRe as $group){
	                			if($group==$resu['WEB_UI_INDEX']){
	                				echo 'checked';
	                			}
	                		}
                		}
                	?>	
                  class="STYLE2" onclick="checkParent('check<?php echo $row['WEB_UI_INDEX'];?>');" value="<?php echo $resu['WEB_UI_INDEX'];?>" />
                 	<?php echo $resu['WEB_UI_NAME'];?>
                </li>
                <?php }?>
              </ul>
            </li>
            <?php 
          		}}
            ?>
             
          </ul>
        </div></td>
      <td style="background: #3980b2;">&nbsp;</td>
    </tr>
    <form action='manageGroup.php' method="post" onsubmit="return CheckSub()">
    	<input type="hidden" name='uiId' id='uiId' value="<?php if(!empty($index)){echo $index;}?>"/>
	    <input type="hidden" name='hidd' id='hidd' value="<?php if(!empty($uiId)){echo $uiId;}?>"/>
	    <tr>
	      <td height="24" style="background: #3980b2;">&nbsp;</td>
	      <td align="center" valign="middle">
	      	<input name="" id="add" type="submit" class="btnbg" value="提交保存"
				style="width: 70px; color: #FFF" />
	        <input name="" id="add" type="button" class="btnbg" value="返回管理"
				style="width: 70px; color: #FFF"
				onclick="javascript:window.location.href='group.php'" />
	        <br />
	        <br /></td>
	      <td height="24" style="background: #3980b2;">&nbsp;</td>
	    </tr>
    </form>
    <tr>
      <td height="24" width="8"><img src="images/user_03.gif" height="24"
			width="8" /></td>
      <td style="background: #3980b2;"></td>
      <td height="24" width="8"><img src="images/user_04.gif" height="24"
			width="8" /></td>
    </tr>
  </table>
</div>
<!--endusrTab-->
<script type="text/javascript"><!--
function checkAllType(checkboxID, boxID){
	var inputArr = document.getElementById(boxID).getElementsByTagName('input');
	if(document.getElementById(checkboxID).checked){
		for(var i=0;i<inputArr.length;i++){
			if(inputArr.item(i).type == 'checkbox'){
				inputArr.item(i).checked = true;
			}
		}
	}else{
		for(var i=0;i<inputArr.length;i++){
			if(inputArr.item(i).type == 'checkbox'){
				inputArr.item(i).checked = false;
			}
		}
	}
	sltAll();
}
function checkA(){
	var inputArr=document.getElementsByName('checkbox');
	if(document.getElementById('checkall').checked){
		for(var i=0;i<inputArr.length;i++){
			if(inputArr.item(i).type=='checkbox'){
				inputArr.item(i).checked=true;
			}
		}
	}else{
		for(var i=0;i<inputArr.length;i++){
			if(inputArr.item(i).type == 'checkbox'){
				inputArr.item(i).checked = false;
			}
		}
	}
	sltAll();
}
//选择父亲节点
function checkParent(parentID){
	if(!document.getElementById(parentID).checked){
		document.getElementById(parentID).checked=true;
	}
	sltAll();
}
function sltAll(){
	$('hidd').val('');
	var $aray = document.getElementsByName("checkbox");
	var $str="";
	var sub=",";
	for(var i=0;i<$aray.length;i++){
		if($aray[i].checked){
			$str+=sub+$aray[i].value;
		}
	}
	if($str==","){
		$("#hidd").val("");
	}else{
		$("#hidd").val($str);
	}
}
function CheckSub(){
	if($('#hidd').val()==""){
		alert('请选择权限后再提交！');
		return false;
	}
	return true;
}
--></script>
